package me.chinaq.fastweb.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;
import org.springframework.web.servlet.NoHandlerFoundException;

import javax.servlet.http.HttpServletRequest;

/**
 * 统一异常拦截处理
 * Created by shaoqi on 2016/10/10.
 */
@RestControllerAdvice
public class ExceptionHandlerAdvice {

	private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionHandlerAdvice.class);

	/**
	 * 统一异常拦截提示
	 *
	 * @param request
	 * @param e
	 * @return
	 */
	@ExceptionHandler(Exception.class)
	public String exceptionHandler(HttpServletRequest request, Exception e) {
		LOGGER.error("系统异常", e);
		//NoHandlerFoundException = 404，没有找到对应的链接
		if (e instanceof NoHandlerFoundException) {

		}
		return "Error";
	}
}
